package be.sc.classicnetwork.service.impl;

import be.sc.classicnetwork.model.Request;
import be.sc.classicnetwork.service.MailService;
import freemarker.template.SimpleHash;

/**
 * 
 */
public class EmailRequestTask implements Runnable {

    private static final String REQUEST_TEMPLATE = "request.ftl";

    private MailService mailService;
    private String adminEmail;
    private Request request;

    /**
     * Constructor.
     */
    public EmailRequestTask(MailService mailService, String adminEmail) {
	super();
	this.mailService = mailService;
	this.adminEmail = adminEmail;
    }

    /**
     * @see java.lang.Runnable#run()
     */
    @SuppressWarnings("unchecked")
    public void run() {
	// put the request info as model for freemarker template
	SimpleHash model = new SimpleHash();
	model.put("request", this.request);

	// send the email
	this.mailService.sendFreeMarkerTemplate(this.adminEmail, "Request: " + this.request.getSubject(), null,
		REQUEST_TEMPLATE, model);

    }

    public void setMailService(MailService mailService) {
	this.mailService = mailService;
    }

    public void setAdminEmail(String adminEmail) {
	this.adminEmail = adminEmail;
    }
}
